/*
 * @(#)Line.java        0.1 09/04/29
 * @version 	0.1 29 Apr 2009
 * @author 	Tran Dai Hiep, Nguyen Thang Huy
 * 
 * Luu tru du lieu cua mot quan he giua 2 class, doc du lieu tu XML
 */


package Data;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import GUI.*;

public class Line {
	public static final int IS_A = 0;
	public static final int HAS_A = 1;
	
	int type;
	ClassFrame head, tail;
	
	public Line(ClassFrame h, ClassFrame t, int _type) throws Exception {
		if (h == null || t == null) throw new Exception("Null ClassFrame");
		head = h;
		tail = t;
		type = _type;
	}
	
	public ClassFrame getHead() {
		return head;
	}
	
	public ClassFrame getTail() {
		return tail;
	}
	
	public int getType() {
		return type;
	}
	
	/*
	 * Chuyen du lieu mot Line thanh XML
	 */
	public Node toXml(Document doc) {
    	Element lineElement = doc.createElement("Line");
    	lineElement.setAttribute("type", type + "");
    	Element headElement = doc.createElement("head");
    	headElement.appendChild(doc.createTextNode(head.getClassData().getId() + ""));
    	lineElement.appendChild(headElement);
    	
    	Element tailElement = doc.createElement("tail");
    	tailElement.appendChild(doc.createTextNode(tail.getClassData().getId() + ""));
    	lineElement.appendChild(tailElement);
    	
    	return lineElement;
	}
}
